<!-- PublicCharts -->
<template>
  <div class="PublicCharts animate__animated animate__zoomIn">
    <div class="PublicCharts-title">
      <div class="h1">{{ this.title }}</div>
    </div>
    <div class="publicChartBox">
      <div :class="'public-info ' + this.id">
        <!--  -->
      </div>
    </div>
    <!-- <div v-if="loadingFlag" class="e-loading">
      <dv-loading>Loading...</dv-loading>
    </div> -->
  </div>
</template>

<script>

export default {
  //import引入的组件需要注入
  components: {},
  data() {
    //这里存放数据
    return {
      loadingFlag: true,
    };
  },
  props: {
    title: String,
    option: Object,
    id: String,
    method: Function
  },
  //监听属性 类似于data概念
  computed: {
    areaCode() {
      return this.$store.state.listAreaIndex;
    },
  },
  //监控data中的数据变化
  watch: {
    areaCode(newVal, oldVal) {
      // console.log("区域code有改动 -- eCharts");
      // console.log(newVal, oldVal);
      // this.init();
    },
  },
  //方法集合
  methods: {
    PublicCharts() {
      let chartBox = document.getElementsByClassName(this.id)[0]
      // console.log("id:" + this.id)
      chartBox.setAttribute("id",this.id)
      const container = document.getElementById(this.id);
      const myChart =  this.$echarts.init(container);
      myChart.setOption(this.option);
      myChart.on("click", this.method)
      this.loadingFlag = false
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    // this.config = this.option
    // this.title = this.msg
    // this.idStr = this.id
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.PublicCharts();
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='less' scoped>
//@import url(); 引入公共css类
.PublicCharts {
  width: 100%;
  height: 100%;
  position: relative;
  .PublicCharts-title {
    // background-color: #141b47;
    color: @FontColor;
    font-size: 0.22rem;
    font-weight: bold;
    height: 15%;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .publicChartBox {
    width: 100%;
    height: 85%;
    position: relative;
    .public-info {
      height: 100%;
      font-size: 0.2rem;
      color: @FontColor;
    }
  }
  .e-loading {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    color: #fff;
  }
}
</style>